<?php


namespace app\api\qqpay;

class Pay
{
	public static function pay($config, $out_trade_no, $amount, $body, $notify_url, $ip = "")
	{
		$qqpay = (new QQPay(["mch_id" => $config["merchant_id"], "key" => $config["apikey"], "notify_url" => $notify_url, "ip" => $ip ? $ip : \think\facade\Request::ip()]))->unifiedOrder(["body" => $body, "out_trade_no" => $out_trade_no, "total_fee" => $amount, "trade_type" => "NATIVE"]);
		if ($qqpay["return_code"] == "SUCCESS" && $qqpay["result_code"] == "SUCCESS") {
			return $qqpay;
		} else {
			return $qqpay["err_msg"];
		}
	}
	public static function getSign($config, $params)
	{
		$sign = (new QQPay(["mch_id" => $config["merchant_id"], "key" => $config["apikey"], "notify_url" => "", "ip" => ""]))->MakeSign($params);
		return $sign;
	}
}